using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Tarea4
{
    class PriorityQueue
    {
        ArrayList items;

        public PriorityQueue()
        {
            items = new ArrayList();
        }

        public StateFifteenManhattan GetMax()
        {
            items.Sort();
            StateFifteenManhattan temp = (StateFifteenManhattan)items[items.Count];
            Delete(temp);
            return temp;
        }

        public StateFifteenManhattan GetMin()
        {
            items.Sort();
            //PrintQueue();
            StateFifteenManhattan temp = (StateFifteenManhattan)items[0];
            //PrintQueue();
            Delete(temp);
            return temp;
        }

        public void Add(StateFifteenManhattan state)
        {
            items.Add(state);
        }

        public void Delete(StateFifteenManhattan state)
        {
            /*
            int index = items.BinarySearch(state);

            for(int i = index; i < items.Count; i++)
                if (state.Equals(items[i]))
                {
                    items.RemoveAt(i);
                    break;
                }
            */

            items.Remove(state);
        }

        public bool IsEmpty
        {
            get { return items.Count < 1; }
        }

        public int Count
        {
            get { return items.Count; }
        }

        public void PrintQueue()
        {
            for (int e = 0; e < items.Count; e++)
            {
                StateFifteenManhattan a = (StateFifteenManhattan) items[e];
                System.Console.WriteLine("Elemento " + e);
                for (int i = 0; i < a.Board.GetLength(0); i++)
                {
                    for (int j = 0; j < a.Board.GetLength(0); j++)
                        System.Console.Write(a.Board[i, j] + "\t");
                    System.Console.WriteLine("");
                }
                System.Console.WriteLine(a.Heuristic + " :: " + a.Index + "\n-------------------------------");
            }
        }
    }
}
